VERSION := 0.83

DESTDIR := /usr/share/php

all:
	@echo 'Targets are'
	@echo '  dist    (generate distribution tarball)'
	@echo '  gendoc  (generate functionr reference documentation)'
	@echo '  manual  (generate DocBook manual)'
	@echo '  phpdoc  (generate Sugar API reference)'
	@echo '  install (install to DESTDIR)'

dist:
	-[ -d sugar-$(VERSION) ] && rm -fr sugar-$(VERSION)/
	mkdir sugar-$(VERSION)/
	cp Sugar.php README LICENSE NEWS Makefile sugar-$(VERSION)/

	mkdir sugar-$(VERSION)/bin/
	cp bin/sugardoc sugar-$(VERSION)/bin/

	mkdir sugar-$(VERSION)/doc/
	cp doc/sugardoc.css doc/sugar-manual.xml sugar-$(VERSION)/doc/

	mkdir sugar-$(VERSION)/Sugar/
	for file in `find Sugar -name '*.php'` ; do install -D "$$file" "sugar-$(VERSION)/$$file" ; done

	mkdir sugar-$(VERSION)/test/
	cp test/index.php test/Test.php test/run-test sugar-$(VERSION)/test/

	mkdir sugar-$(VERSION)/test/plugins/
	cp test/plugins/*.php sugar-$(VERSION)/test/plugins/

	mkdir sugar-$(VERSION)/test/tpl/
	cp test/tpl/*.tpl sugar-$(VERSION)/test/tpl/

	mkdir sugar-$(VERSION)/test/tests/
	cp test/tests/*.php sugar-$(VERSION)/test/tests/
	cp test/tests/*.tpl sugar-$(VERSION)/test/tests/
	cp test/tests/*.txt sugar-$(VERSION)/test/tests/

	mkdir sugar-$(VERSION)/test/cache/

	tar -zcf sugar-$(VERSION).tar.gz sugar-$(VERSION)/
	rm -fr sugar-$(VERSION)/

gendoc:
	[ -d doc ] || mkdir doc
	php tools/gen-doc.php > doc/reference.html

manual:
	[ -d doc/manual ] && rm -fr doc/manual
	mkdir doc/manual
	xmlto html doc/sugar-manual.xml -o doc/manual

phpdoc:
	phpdoc -ti 'Sugar Template Engine' -o HTML:frames:default -f Sugar.php \
			-q -d Sugar -t doc/phpdoc

install:
	mkdir -p $(DESTDIR)/Sugar
	cp Sugar/*php $(DESTDIR)/Sugar
	cp Sugar.php $(DESTDIR)/Sugar.php
